// 垃圾小工具包


//通用弹出提示框
const showToast = function (msg) {
    console.log(msg);
    var tipsHtml = "<div class=\'tips-pop\' id=\'tipsPop\'>" + msg + "</div>"
    $("body").append(tipsHtml);
    setTimeout(() => {
        $("#tipsPop").fadeOut(800).remove();
    }, 1000);
}

//回到登录界面
const toLogin = function () {
    console.log("跳转登录页面");
    this.$router.push({ path: '/' })
}

//文本超出滚动
const overTextScroll= function() {
    var overTxtObj = $(".over-text");
    var overTxt = overTxtObj.html();
    var overTxtHeight = overTxtObj.height();
    var overTxtWidth = overTxtObj.width();
    overTxtObj.css({
      height: overTxtHeight,
      width: overTxtWidth
    });
    var overTxtCont =
      "<span id='newOverTxt' style=' position: absolute; left: 0px;'>" +
      overTxt +
      "</span>";
    overTxtObj.html(overTxtCont);
    var newOverTxtWidth = $("#newOverTxt").width();
    var leftText = overTxtWidth - newOverTxtWidth;
    function getPositLeft() {
      var txtLeft = $("#newOverTxt").position().left;//这狗玩意儿能运行，但是要报错
      if (txtLeft == 0) {
        setTimeout(() => {
          $("#newOverTxt").css({
            left: leftText
          });
          getPositLeft();
        }, 1000);
      } else if (txtLeft == txtLeft) {
        setTimeout(() => {
          $("#newOverTxt").css({
            left: 0
          });
          getPositLeft();
        }, 8000);
      }
      return txtLeft;
    }
    setInterval(getPositLeft(), 8000);
}

//数字格式化
const numberForamt = function(number){
  if(number < 10000){
    return number;
  }
  else{
    var number = number/10000
    return number.toFixed(2) + "万"
  }
}


export {
    showToast,
    toLogin,
    overTextScroll,
    numberForamt
}